/**
 * Created with JetBrains WebStorm.
 * User: thaidoanhong
 * Date: 3/25/13
 * Time: 10:25 PM
 * To change this template use File | Settings | File Templates.
 */
/**
 * Created with JetBrains WebStorm.
 * User: thaidoanhong
 * Date: 3/25/13
 * Time: 10:25 PM
 * To change this template use File | Settings | File Templates.
 */
var MyAttributeList = Class.create({
    initialize: function(element){
        this.attributes = new Array();
        this.element = element;
    },
    add: function(o){
        this.attributes.push(o);
    },
    getValueFromKey: function(key){
        for(var i=0;i<this.attributes.length;i++){
            if(this.attributes[i].key == key){
                return this.attributes[i].value;
            }
        }
        return null;
    },
    getValueFromName : function(name){
        for(var i=0;i<this.attributes.length;i++){
            if(this.attributes[i].name == name){
                return this.attributes[i].value;
            }
        }
        return null;
    },
    setValueByKey: function(key, value){
        for(var i=0;i<this.attributes.length;i++){
            if(this.attributes[i].key == key){
                this.attributes[i].value = value;
                return true;
            }
        }
        return false;
    },
    setValueByName: function(name, value){
        for(var i=0;i<this.attributes.length;i++){
            if(this.attributes[i].name == name){
                this.attributes[i].value = value;
                return true;
            }
        }
        return false;
    },
    getAttributeFromKey: function(key){
        for(var i=0;i<this.attributes.length;i++){
            if(this.attributes[i].key == key){
                return this.attributes[i];
            }
        }
        return null;
    },
    getAttributeFromName: function(name){
        for(var i=0;i<this.attributes.length;i++){
            if(this.attributes[i].name == name){
                return this.attributes[i];
            }
        }
        return null;
    },
    getSize: function(){
        return this.attributes.length;
    },
    toDataObjectArray: function(isExport){
        var attrsDataObject = new Array();

        for(var i = 0; i < this.attributes.length; i++){
            attrsDataObject.push(this.attributes[i].toDataObject(isExport));
        }

        return attrsDataObject;
    },
    clear: function(){
        this.attributes.clear();
    }
})